package com.ruoyi.jiuzai.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jiuzai.domain.Wuzichuku;
import com.ruoyi.jiuzai.service.IWuzichukuService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物资出库Controller
 * 
 * @author ruoyi
 * @date 2025-06-21
 */
@RestController
@RequestMapping("/jiuzai/chuku")
public class WuzichukuController extends BaseController
{
    @Autowired
    private IWuzichukuService wuzichukuService;

    /**
     * 查询物资出库列表
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:chuku:list')")
    @GetMapping("/list")
    public TableDataInfo list(Wuzichuku wuzichuku)
    {
        startPage();
        List<Wuzichuku> list = wuzichukuService.selectWuzichukuList(wuzichuku);
        System.out.println("数据--------"+list);
        return getDataTable(list);
    }

    /**
     * 导出物资出库列表
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:chuku:export')")
    @Log(title = "物资出库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Wuzichuku wuzichuku)
    {
        List<Wuzichuku> list = wuzichukuService.selectWuzichukuList(wuzichuku);
        ExcelUtil<Wuzichuku> util = new ExcelUtil<Wuzichuku>(Wuzichuku.class);
        util.exportExcel(response, list, "物资出库数据");
    }

    /**
     * 获取物资出库详细信息
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:chuku:query')")
    @GetMapping(value = "/{cId}")
    public AjaxResult getInfo(@PathVariable("cId") Long cId)
    {
        System.out.println("数据--------"+wuzichukuService.selectWuzichukuByCId(cId));
        return success(wuzichukuService.selectWuzichukuByCId(cId));
    }

    /**
     * 新增物资出库
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:chuku:add')")
    @Log(title = "物资出库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Wuzichuku wuzichuku)
    {
//        return toAjax(wuzichukuService.insertWuzichuku(wuzichuku));

        int rows = wuzichukuService.insertWuzichuku(wuzichuku);
        if (rows > 0) {
            // 返回包含生成ID的完整实体
            return success(wuzichuku);
        }
        return error("新增失败");

    }

    /**
     * 修改物资出库
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:chuku:edit')")
    @Log(title = "物资出库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Wuzichuku wuzichuku)
    {
        return toAjax(wuzichukuService.updateWuzichuku(wuzichuku));
    }

    /**
     * 删除物资出库
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:chuku:remove')")
    @Log(title = "物资出库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cIds}")
    public AjaxResult remove(@PathVariable Long[] cIds)
    {
        return toAjax(wuzichukuService.deleteWuzichukuByCIds(cIds));
    }
}
